package com.sanjiahantang.youjiarole.module.store.views.impl;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.CameraUpdate;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.CameraPosition;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.module.store.preseneters.StorePresenter;
import com.sanjiahantang.youjiarole.module.store.views.StoreView;


/**
 * Created by zy on 2017/9/20.
 */

public class StoreOnMapActivity extends BaseMvpActivity<StoreView,StorePresenter> implements StoreView, View.OnClickListener {

    private MapView mapView;
    private CameraUpdate cameraUpdate;
    private AMap aMap;
    private View back,right;


    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public StorePresenter initPresenter() {
        return new StorePresenter();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mapView.onCreate(savedInstanceState);
        if (mapView != null){
            aMap = mapView.getMap();
        }
        cameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(39.92790482, 116.39602661), 18, 0, 30));
        aMap.moveCamera(cameraUpdate);
        Marker marker = aMap.addMarker(new MarkerOptions()
                .position(new LatLng(39.92790482, 116.39602661))
//                .title("体验店")
                .icon(BitmapDescriptorFactory
                        .fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.i_close)))
                .draggable(true));
        marker.showInfoWindow();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_store_on_map);
        back = findViewById(R.id.fl_Left);
        right = findViewById(R.id.flIcon1);
        ImageView iv = (ImageView) findViewById(R.id.icon1);
        iv.setImageResource(R.drawable.i_refresh);
        iv.setVisibility(View.VISIBLE);
        back.setOnClickListener(this);
        right.setOnClickListener(this);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("体验店");

        mapView = (MapView) findViewById(R.id.mapView);
    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.fl_Left:
                finish();
                break;
            case R.id.flIcon1:
                aMap.moveCamera(cameraUpdate);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }
}
